<html><head><title>BindGadgetEvent.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - BindEvent and  BindGadgetEvent example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;

</font><font color="#3A3966">; Let's create a custom TrackBar gadget with a Canvas gadget.

</font>
<b><font color="#3A3966">Procedure</font></b> <font color="#3A3966">RepaintCanvas</font>(x)
  <font color="#3A3966">; Paint a canvas which looks like a Trackbar  
</font>  <b><font color="#3A3966">If</font></b> <font color="#3A3966">StartDrawing</font>(<font color="#3A3966"> CanvasOutput</font>(0) )
<font color="#3A3966">    Box</font>(0,0,<font color="#3A3966">OutputWidth</font>(),<font color="#3A3966">OutputHeight</font>(),<font color="#3A3966">RGB</font>($FF,$FF,$FF))
<font color="#3A3966">    DrawingMode</font>(<font color="#924B72">#PB_2DDrawing_Gradient</font>)
<font color="#3A3966">    BackColor</font>(<font color="#3A3966">RGB</font>($40,$40,$40))
<font color="#3A3966">    FrontColor</font>(<font color="#3A3966">RGB</font>($DD,$DD,$DD))
<font color="#3A3966">    LinearGradient</font>(0, 0,<font color="#3A3966"> OutputWidth</font>(),<font color="#3A3966"> OutputHeight</font>())
<font color="#3A3966">    Box</font>(0,0,<font color="#3A3966">OutputWidth</font>(),<font color="#3A3966">OutputHeight</font>())
<font color="#3A3966">    DrawingMode</font>(<font color="#924B72">#PB_2DDrawing_Default</font>)
<font color="#3A3966">    Box</font>(x,0,<font color="#3A3966">OutputWidth</font>()-x,<font color="#3A3966">OutputHeight</font>(),<font color="#3A3966">RGB</font>($FF,$FF,$FF))
<font color="#3A3966">    Box</font>(x-3,0,5,<font color="#3A3966">OutputHeight</font>(),<font color="#3A3966">RGB</font>($00,$00,$00))
<font color="#3A3966">    StopDrawing</font>()
  <b><font color="#3A3966">EndIf</font></b>
  <b><font color="#3A3966">Debug</font></b> x
<b><font color="#3A3966">EndProcedure</font></b>

<b><font color="#3A3966">Procedure</font></b> <font color="#3A3966">OnLeftClick</font>()
  <font color="#3A3966">; Left click on the canvas  
</font><font color="#3A3966">  RepaintCanvas</font>(<font color="#3A3966"> GetGadgetAttribute</font>(0,<font color="#924B72">#PB_Canvas_MouseX</font>) )
<b><font color="#3A3966">EndProcedure</font></b>

<b><font color="#3A3966">Procedure</font></b> <font color="#3A3966">OnMouseMove</font>()
  <font color="#3A3966">; Left click + move on the mouse on the canvas  
</font>  <b><font color="#3A3966">If</font></b> <font color="#3A3966">GetGadgetAttribute</font>(0,<font color="#924B72">#PB_Canvas_Buttons</font>) &amp; <font color="#924B72">#PB_Canvas_LeftButton</font>
    x =<font color="#3A3966"> GetGadgetAttribute</font>(0,<font color="#924B72">#PB_Canvas_MouseX</font>)
    <b><font color="#3A3966">If</font></b> x &lt; 0 : x = 0 : <b><font color="#3A3966">EndIf</font></b>
    <b><font color="#3A3966">If</font></b> x &gt;<font color="#3A3966"> GadgetWidth</font>(0) : x =<font color="#3A3966"> GadgetWidth</font>(0) : <b><font color="#3A3966">EndIf</font></b>
<font color="#3A3966">    RepaintCanvas</font>( x )
  <b><font color="#3A3966">EndIf</font></b>
<b><font color="#3A3966">EndProcedure</font></b>

 <font color="#3A3966">; Let's open a windows with a canvas
</font><b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindow</font>(0, 0, 0, 220, 120, &quot;BindGadgetEvent&quot;, <font color="#924B72">#PB_Window_SystemMenu</font> | <font color="#924B72">#PB_Window_ScreenCentered</font>)
<font color="#3A3966">  CanvasGadget</font>(0, 10, 10, 200, 20)
  
<font color="#3A3966">  RepaintCanvas</font>(50) <font color="#3A3966">; Paint the canvas and set the tracker at 50
</font>  
<font color="#3A3966">  BindGadgetEvent</font>(0, @OnLeftClick(),<font color="#924B72">#PB_EventType_LeftClick</font>) <font color="#3A3966">; Bind canvas left click 
</font><font color="#3A3966">  BindGadgetEvent</font>(0, @OnMouseMove(),<font color="#924B72">#PB_EventType_MouseMove</font>) <font color="#3A3966">; Bind mouse move on the canvas
</font>  
  <b><font color="#3A3966">Repeat</font></b> : <b><font color="#3A3966">Until</font></b> <font color="#3A3966">WaitWindowEvent</font>() = <font color="#924B72">#PB_Event_CloseWindow</font>
<b><font color="#3A3966">EndIf</font></b>

</font></pre>
</body></html>
